package Servlet;

import com.alibaba.fastjson.JSONArray;
import dao.MyConnection;
import com.alibaba.fastjson.JSONObject;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class deleteServlet extends HttpServlet {

    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setHeader("Cache-Control", "no-cache");
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        MyConnection myCon = new MyConnection();
        myCon.getConnection();
        int res = -1;
        try {
            PreparedStatement ps = myCon.connection.prepareStatement("Delete from appointment where appointmenttime<DATE_SUB(CURRENT_DATE(),INTERVAL 10 day)");
            PreparedStatement ps1 = myCon.connection.prepareStatement("Delete from rental where borrowdate<DATE_SUB(CURRENT_DATE(),INTERVAL 10 day)");
            res = ps.executeUpdate();
            res = ps1.executeUpdate();
            ps.close();
            ps1.close();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            myCon.closeConnection();
        }
        out.print(res);
    }
}
